<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title>登录</title>
	<link rel="stylesheet" href="/component/pear/css/pear.css" />
	<link rel="stylesheet" href="/admin/css/other/login.css" />
	<link rel="stylesheet" href="/admin/css/variables.css" />
	<link rel="stylesheet" href="https://at.alicdn.com/t/c/font_4712544_4xg0e15nlqr.css" />

	<script>if (window.self != window.top) { top.location.reload();}</script>
	<style>
		.other-login-methods{
			span{
				margin-left: 10px;
				cursor:pointer;
			}
			span:hover{
				margin-left: 10px;
				font-size: 18px;
			}
		}
	</style>
</head>

<body>
	<div class="login-page" style="background-image: url(./admin/images/background.svg)">
		<div class="layui-row">
			<div class="layui-col-sm6 login-bg layui-hide-xs">
				<img class="login-bg-img" src="/img/bg.png" alt="" />
			</div>
			<div class="layui-col-sm6 layui-col-xs12 login-form">
				<div class="layui-form">
					<div class="form-center">
						<div class="form-center-box">
							<div class="top-log-title">
								<img class="top-log" src="/img/logo.png" alt="" />
								<span>简易成绩管理系统</span>
							</div>
							<div class="top-desc">
								欢迎使用 简易成绩管理系统
							</div>
							<div style="margin-top: 30px;">
								<div class="layui-form-item">
									<div class="layui-input-wrap">
										<div class="layui-input-prefix">
											<i class="layui-icon layui-icon-username"></i>
										</div>
										<input lay-verify="required" name="account" placeholder="学工号/用户名" autocomplete="off"
											class="layui-input">
									</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-input-wrap">
										<div class="layui-input-prefix">
											<i class="layui-icon layui-icon-password"></i>
										</div>
										<input type="password" name="password" value=""
											lay-verify="required|confirmPassword" placeholder="密码" autocomplete="off"
											class="layui-input" lay-affix="eye">
									</div>
								</div>
								<div class="layui-form-item">
									<div  style="display: flex; border: rgb(210, 210, 210) solid 1px;border-radius: 4px;">
										<i class="layui-icon layui-icon-user" style="padding-left:14px;padding-right:20px;display: flex; align-items: center"></i>
										<div style="width: 100%;">
											<select lay-verify="required" name="roleType">
												<option value="1" >教师</option>
											</select>
										</div>
									</div>

								</div>
								<div class="login-btn">
									<button type="button" lay-submit lay-filter="login" class="layui-btn login">登 录</button>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- 资 源 引 入 -->
	<script src="./component/layui/layui.js"></script>
	<script src="./component/pear/pear.js"></script>
	<script src="/js/cookie.js"></script>
	<script>
		let checkCodeUrl="";
		const changeCheckCode=()=>{
			checkCodeUrl="/account/checkCode?"+new Date().getTime();
			document.getElementById("checkCode").src=checkCodeUrl;
		}

		const changeOfType=(type)=>{
			alert("你没账号，我也没办法发噶，自己联系管理员吧");
		}

		layui.use(['form', 'button', 'jquery','popup'], function () {
			var form = layui.form;
			var button = layui.button;
			var popup = layui.popup;
			var $=layui.jquery;
			// 登 录 提 交
			form.on('submit(login)', function (data) {
				/// 验证
				event.preventDefault();
				// 提交表单
				// 获取表单数据
				let formData=data.field;
				var request = $.ajax({
					url: "/account/login",
					method: "POST",
					data: formData,
				});

				// 请求成功
				request.done(function( res ) {
					console.log(res);
					if (res.code===null||res.code!==200){
						popup.warning(res.info, function () {
							console.log(res.info);
						});
						changeCheckCode();
					}
					if (res.code!==200){
						return;
					}

					// if(formData.rememberMe){
					// 	// 存入cookie
					// 	setCookie("loginInfo",JSON.stringify(res),14);
					// }else{
					// 	deleteCookie("loginInfo");
					// }

					// 存入登录信息
					localStorage.setItem("userInfo",JSON.stringify(res.info));
					/// 动画
					button.load({
						elem: '.login',
						time: 500,
						done: function () {
							popup.success("登录成功", function () {
								location.href = "/index"
							});
						}
					})
				});

				// 请求失败
				request.fail(function( jqXHR, textStatus ) {
					console.error(jqXHR,textStatus);
				});
				return false;
			});
		})

		// 记住我
		const initLoginInfo=()=>{

		}
	</script>
</body>

</html>
